package shuai.test;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import shuai.biz.UserBiz;
import shuai.model.User;

public class Demo {
	@Test
	public void test1(){
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		UserBiz  biz=ac.getBean("userBiz",UserBiz.class);
		User user=new User("kkk","kkk",22);
		biz.addUser(user);
	}
	
	@Test
	public void test2(){
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		UserBiz biz=ac.getBean("userBiz",UserBiz.class);
		List<User> list=new ArrayList<User>();
		for(int i=0;i<2;i++){
			User user=new User();
			user.setUsername("kong"+i);
			user.setPassword("kong"+i);
			user.setAge(18+i);			
			list.add(user);
		}
		biz.addUsers(list);
	}
	
	@Test
	public void test3(){
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
		UserBiz biz=ac.getBean("userBiz",UserBiz.class);
		User user=new User();
		user.setUsername("k");
		List<User> list=biz.searchUser(user);
		for(User u:list){
			System.out.println(u.getUsername()+u.getAge());
		}
	}

}
